package net.anzhuo.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsHonorsMapper;
import net.anzhuo.entity.GsHonors;
import net.anzhuo.service.GsHonorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class GsHonorsServiceImpl implements GsHonorsService {

	@Autowired
	private GsHonorsMapper gsHonorsMapper;

	@Override
	public PaginationVO<GsHonors> getListWithPage(GsHonors gsHonors) {
		PaginationVO<GsHonors> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsHonorsMapper.getListWithPage(gsHonors));
		paginationVO.setTotalCount(gsHonorsMapper.getCount(gsHonors));
		paginationVO.setTotalPage((gsHonorsMapper.getCount(gsHonors) + gsHonors.getPageSize() -1)  / gsHonors.getPageSize());
		paginationVO.setPageNo(gsHonors.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsHonors> getByMd5(String md5) {
		return gsHonorsMapper.getByMd5(md5);
	}

	@Override
	public GsHonors getById(Long id) {
		return gsHonorsMapper.getById(id);
	}

	@Override
	public List<GsHonors> getList() {
		return gsHonorsMapper.getList();
	}

	@Override
	public List<GsHonors> getList(GsHonors gsHonors) {
		return gsHonorsMapper.getListByQuery(gsHonors);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsHonors gsHonors) {
		gsHonorsMapper.update(gsHonors);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsHonors gsHonors) {
		gsHonorsMapper.save(gsHonors);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(GsHonors gsHonors) {
		gsHonorsMapper.delete(gsHonors);
	}
}
